#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL p=1e5+10;
LL T,n,a[p],myans;
struct node
{
    LL last,val;
};
node dp[p][2];
LL maxx(LL x,LL y)
{
    if(x>y) return x;
    return y;
}
inline void dfs(LL ip,LL last1,LL last2,LL ans)
{
    if(ip==n+1)
    {
        myans=maxx(ans,myans);
        return;
    }
    dfs(ip+1,ip,last2,ans+a[ip]*(a[ip]==a[last1]));
    dfs(ip+1,last1,ip,ans+a[ip]*(a[ip]==a[last2]));
}
int main()
{
    freopen("color1.in","r",stdin);
    //freopen("color.out","w",stdout);

    scanf("%lld",&T);
    while(T--)
    {
        myans=0;
        scanf("%lld",&n);
        for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
        dfs(1,0,0,0);
        /*memset(dp,0,sizeof(dp));
        dp[2][1].last=a[1];
        dp[2][0].last=a[1];
        for(int i=3;i<=n;i++)
            for(int k=0;k<=1;k++)
                {
                    LL used;
                    if(dp[i-1][k^1].last==a[i]) used=a[i];
                    if(dp[i][k].val<dp[i-1][k^1].val+used)
                    {
                        dp[i][k].val=dp[i-1][k^1].val+used;
                        dp[i][k].last=a[i-1];
                    }
                    used=0;
                    if(a[i-1]==a[i]) used=a[i];
                    if(dp[i][k].val<dp[i-1][k].val+used)
                    {
                        dp[i][k].val=dp[i-1][k].val+used;
                        dp[i][k].last=dp[i-1][k].last;
                    }
                    //cout<<i<<' '<<dp[i][k].val<<' '<<dp[i][k].last<<endl;
                }*/
        printf("%lld\n",myans);
    }
    return 0;
}
